package reader;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

public class ReaderReset {
	
	public void run(){
		String input = "asdfghjkl1234567890";
		StringReader reader = new StringReader(input);
		int c = -1;
		try {
			 c = reader.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		while(c>0){
			System.out.println((char)c);
			try {
				c = reader.read();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		try {
			reader.reset();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			c = reader.read();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		while(c>0){
			System.out.println("Round 2:\t" +(char)c);
			try {
				c = reader.read();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		try {
			reader.reset();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			c = reader.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		for(int i = 0; i < 4; i++){
			System.out.println("Round 3 OUTSIDE :\t" + (char) c);
			try {
				c = reader.read();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		readRest(c, reader);
		try {
			reader.reset();
		} catch (IOException e) {
			e.printStackTrace();
		}
		skipAndThenReadCharacters(3, reader);
	}
	
	private void skipAndThenReadCharacters(int i, StringReader reader) {
		try {
			reader.skip(i);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		int c = -1;
		try {
			c = reader.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		while(c>0){
			System.out.println("Round 4 Skipped:\t" + (char) c);
			try {
				c = reader.read();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	private void readRest(int c, Reader reader) {
		while(c > 0 ){
			System.out.println("Round 3:\t" + (char) c);
			try {
				c = reader.read();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		ReaderReset rr = new ReaderReset();
		rr.run();
	}

}
